package com.woniuxy.propertyjava.controller;

import com.woniuxy.propertyjava.entity.Deliver;
import com.woniuxy.propertyjava.entity.PageBean;
import com.woniuxy.propertyjava.entity.ResponseResult;
import com.woniuxy.propertyjava.service.DeliverService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Created by IntelliJ IDEA.
 *
 * @Author : author
 * @create 2022/7/5 15:14
 */
@RestController
public class DeliverController {
    @Autowired
    DeliverService deliverService;

    @PostMapping("/deliver/{pageIndex}/{pageSize}")
    public ResponseResult<PageBean<Deliver>> getDeliversByPage(@PathVariable("pageIndex") int pageIndex,
                                                               @PathVariable("pageSize") int pageSize,
                                                               @RequestBody Deliver deliver) {
        PageBean<Deliver> pageBean = deliverService.getDeliverPageBean(deliver, pageIndex, pageSize);
        ResponseResult<PageBean<Deliver>> responseResult = new ResponseResult<PageBean<Deliver>>(200, "ok", pageBean);
        return responseResult;
    }

    @PostMapping("/deliver")
    public ResponseResult addDeliver(@RequestBody Deliver deliver) {
        deliverService.insertDeliver(deliver);
        ResponseResult responseResult = new ResponseResult<>(200, "添加成功", null);
        return responseResult;
    }

    @PutMapping("/deliver")
    public ResponseResult changeDeliver(@RequestBody Deliver deliver) {
        deliverService.updataDeliver(deliver);
        ResponseResult responseResult = new ResponseResult<>(200, "修改成功", null);
        return responseResult;
    }

    @DeleteMapping("/deliver/{deliverId}")
    public ResponseResult reduceDeliver(@PathVariable("deliverId") int deliverId) {
        deliverService.deleteDeliver(deliverId);
        ResponseResult responseResult = new ResponseResult<>(200, "删除成功", null);
        return responseResult;
    }
}
